home *** CD-ROM | disk | FTP | other *** search
- /* tcaptest.c (c) Copyright 1990 H.Rogers */
-
- /* This program tests the termcap(3) library routines. */
- /* For full information on termcap, read the appropriate entries
- * in sections 3 and 5 of the UNIX Programmer's Manual. */
-
- #include <stdio.h> /* standard I/O and UNIX */
- #include <stdlib.h> /* standard library */
-
- #include "termcap.h" /* screen handling functions */
-
- #ifndef EMULATE
- #include "termio.h" /* terminal I/O */
-
- extern int ioctl(int,int,void *);
- #endif
-
- short ospeed; /* terminal speed */
- char PC,*BC,*UP; /* terminal capabilities */
- static char *CL,*CM,*SO,*SE;
- static int LI,CO;
-
- static char tent[1024]; /* terminal entry buffer */
- static char tbuf[512]; /* terminal capabilities buffer */
- static char *tbufp; /* index pointer for '' */
-
- int out(char); /* single character output function */
-
- int main()
- {
- int i,j; /* general purpose */
- int fd; /* file descriptor of tty */
- #ifndef EMULATE
- struct termio t[1]; /* terminal I/O control structure */
- #endif
-
- if (tgetent(tent,getenv("TERM")) < 1) /* get terminal entry */
- {
- fprintf(stderr,"tcaptest: tgetent returned < 1 (have you set TERM ?)\n");
- exit(1);
- }
-
- tbufp = tbuf; /* initialise index pointer */
-
- if (tgetflag("pc")) /* get 'pc' capability */
- PC = *tgetstr("pc",&tbufp); /* PC is a library variable */
- else
- PC = '\000'; /* defaults to '\000' */
- if (tgetflag("bs")) /* get 'bs' capability */
- BC = "\010"; /* 'bs' capability => BC = "\010" */
- else
- BC = tgetstr("bc",&tbufp); /* get 'bc' capability since no 'bs' */
- UP = tgetstr("up",&tbufp); /* get 'up' - move cursor up */
- CL = tgetstr("cl",&tbufp); /* get 'cl' - clear screen */
- CM = tgetstr("cm",&tbufp); /* get 'cm' - cursor motion */
- SO = tgetstr("so",&tbufp); /* get 'so' - start 'standout' mode */
- SE = tgetstr("se",&tbufp); /* get 'se' - end 'standout' mode */
-
- LI = tgetnum("li"); /* get 'li' - number of lines */
- CO = tgetnum("co"); /* get 'co' - number of columns */
-
- /* now check all capabilities were present */
-
- if ((!BC) || (!UP) || (!CL) || (!CM) || (!SO) || (!SE))
- {
- fputs("tcaptest: terminal must have bc, up, cl, cm, so, and se\n",stderr);
- exit(1);
- }
-
- #ifndef EMULATE
- fd = fileno(stdout); /* get terminal file descriptor */
- ioctl(fd,TCGETA,t); /* get terminal I/O control */
- ospeed = t->c_cflag & CBAUD; /* set ospeed to baud rate */
- t->c_oflag &= (~XTABS); /* turn off XTABS for termcap */
- ioctl(fd,TCSETA,t); /* set terminal I/O control */
- #endif
-
- tputs(CL,0,out); /* clear screen */
- for(i = 0; i < LI - 2; i++)
- {
- j = (i<<1); if (j > CO - 6) j = CO - 6;
- tputs(tgoto(CM,j,i),0,out); /* goto ((i << 1), i) */
- fputs("Hi..",stdout); /* print "Hi.." */
- tputs(SO,0,out); /* start 'standout' mode */
- j = CO - 6 - (i<<1); if (j < 0) j = 0;
- tputs(tgoto(CM,j,i),0,out); /* goto (74 - (i << 1), i) */
- fputs("Hi..",stdout); /* print "Hi.." */
- tputs(SE,0,out); /* end 'standout' mode */
- }
- printf("\ncolumns: %d\tlines: %d\n",CO,LI);
- }
-
- int out(char c) /* write character to terminal */
- {
- return(putchar(c)); /* use putchar() */
- }
-